/*
 * 组件注释
 * @Author: machinist_wq
 * @Date: 2022-05-03 12:50:21
 * @LastEditors: machinist_wq
 * @LastEditTime: 2023-03-22 19:44:22
 * @Description: 入口文件，所有全局文件统一
 * 人生无常！大肠包小肠......
 */
import { Fragment, StrictMode, FC, ReactElement, Suspense } from "react";
import * as ReactDOM from "react-dom/client";
import { BrowserRouter, useRoutes, Link, HashRouter } from "react-router-dom";
import routes from "@/routes";
import Loading from "@/component/loading";
import { ConfigProvider, Space, Button } from "antd";
import zhCN from "antd/lib/locale/zh_CN";
// import { ChangeButton, SearchForm } from "@/component";
import "antd/dist/antd.css";
import "@/utils";

const RoutePages: FC = (): ReactElement => {
  const element = useRoutes(routes);
  return (
    <Fragment>
      <ConfigProvider locale={zhCN}>
        <Space>
          <Link to={"/components"}>
            <Button type="primary">组件库</Button>
          </Link>
          <Link to={"/react-grid-layout"}>
            <Button type="primary">拖拽库</Button>
          </Link>
          <Link to={"/bpmn"}>
            <Button type="primary">流程图</Button>
          </Link>

        </Space>
        <Suspense fallback={<Loading spinning />}>{element}</Suspense>
      </ConfigProvider>
    </Fragment>
  );
};

const App: FC = (): ReactElement => {
  return (
    <BrowserRouter>
      <RoutePages />
    </BrowserRouter>
  );
};

//要实现局部热更新，必须要添加此句
if ((module as any).hot) {
  (module as any).hot.accept();
}

// // WorkboxWebpackPlugin 注册
// if ("serviceWorker" in navigator) {
//   window.addEventListener("load", () => {
//     navigator.serviceWorker
//       .register("/service-worker.js")
//       .then(registration => {
//         // console.log("SW registered: ", registration);
//       })
//       .catch(registrationError => {
//         // console.log("SW registration failed: ", registrationError);
//       });
//   });
// }

const container = document.getElementById("root")!;
ReactDOM.createRoot(container).render(
  <StrictMode>
    <App />
  </StrictMode>
);
